package com.zy.portal.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zy.pojo.TbItem;
import com.zy.portal.pojo.ItemInfo;
import com.zy.portal.service.ItemService;

@Controller
public class ItemController {
	@Autowired
	private ItemService itemService;

	/*
	 * 首页搜索跳转
	 */
	@RequestMapping("/item/{itemId}")
	public String showItem(@PathVariable Long itemId, Model model) {

		TbItem itemInfo = itemService.getItemById(itemId);
		model.addAttribute("item", itemInfo);
		// 跳转页面springmvc 拦截路径 /item/**,查看是否登录进入LoginInterceptor.java验证
		return "item";
	}
	/*
	 * 点击图片查看详细信息
	 */
	// 防止响应乱码
	@RequestMapping(value = "/item/desc/{itemId}", produces = MediaType.TEXT_HTML_VALUE + ";charset=utf-8")
	@ResponseBody
	public String getItemDesc(@PathVariable Long itemId) {
		String itemDescById = itemService.getItemDescById(itemId);
		return itemDescById;

	}
}
